<html>
<head>
    <title>WebChat | 注册</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../view/statics/source/css/login.css" rel='stylesheet' type='text/css' />
    <script src="../view/statics/plugins/jquery/jquery-2.1.4.min.js"></script>
    <script src="../view/statics/plugins/layer/layer.js"></script>
</head>
<body>

<h1>WebChat</h1>
<div class="login-form">
    <div class="close"> </div>
    <div class="head-info">
        <label class="lbl-1"></label>
        <label class="lbl-2"></label>
        <label class="lbl-3"></label>
    </div>
    <div class="clear"> </div>
    <div class="avtar"><img src="/view/statics/source/img/avtar.png" alt="点我注册"/></div>

        <div class="key"   >
            <input type="text" id="username" name="userid" placeholder="请输入账号" >
        </div>
        <div class="key" >
            <input type="password" id="password" name="password" placeholder="请输入密码">
        </div>

        <div class="signin">
            <input type="button" id="submit" onclick="checkLoginForm()" value="Register" />
        </div>
</div>

<script>



    /**
     * check the login form before user login.
     * @returns {boolean}
     */
    function checkLoginForm(){
        var userid = $('#username').val();
        alert(userid);
        var password = $('#password').val();
        alert(password);
        if(isNull(userid) && isNull(password)){
            alert("账号,密码不能为空");
        }
        if(isNull(userid)){
            alert("账号不能为空");
        }
        if(isNull(password)){
            alert("密码不能为空");
        }
        var data = {"userid":userid,"password":password};
        alert(data);
        $.ajax({

            type:"post",
            url:"/user/chatuser",
            async:true,
            data:JSON.stringify(data),
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success:function (data) {
                if(data.status=="false"){
                    alert("注册失败");
                }
                if(data.status=="true"){
                    alert("注册成功");
                }
            }
        });

    }

    /**
     * check the param if it's null or '' or undefined
     * @param input
     * @returns {boolean}
     */
    function isNull(input){
        if(input == null || input == '' || input == undefined){
            return true;
        }
        else{
            return false;
        }
    }
</script>
</body>
</html>